Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finishing the chalenge #1517

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

italomagno
Copy link

Copy link

@raulriato raulriato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're in the way. Good job!

Just need a few changes

editingTodosId: number[];
setTodos: (todos: Todo[]) => void;
setFilteredTodos: (todos: Todo[]) => void;
setIsActiveFilter: (isActive: boolean) => void;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not using the setIsActiveFilter in the header, so it shouldn't be in the declaration of the props type

src/App.tsx Outdated
editingTodosId={editingTodosId}
setTodos={setTodos}
setFilteredTodos={setFilteredTodos}
setIsActiveFilter={setIsActiveFilter}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has no effect to sen setIsActiveFilter if you are not using it in the header

src/App.tsx Outdated
const [filteredTodos, setFilteredTodos] = useState<Todo[]>([]);
const [error, setError] = useState<string | null>(null);
const [editingTodosId, setEditingTodosId] = useState<number[]>([]);
const [isActiveFilter, setIsActiveFilter] = useState(false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct me if I'm wrong. This variable refers to the state of the footer, right? Whether if it should be rendered or not. If that's so, you could name it better, to something like isFooterActive and setIsFooterActive, you don't need the Filter because it is a boolean state, so it has only two possible states, and it's better to use the Footer in the name to make ir more specific

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way it is, it can be confusing because you actually have a Active filter on the application

src/App.tsx Outdated
if (filter === 'active') {
setFilteredTodos(prev => prev.filter(t => !t.completed));
}
}, [filter, filteredTodos, todos]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a good idea to have the filteredTodos as a dependency here. It causes your list to not render all the todos when you change the filter from Active/Completed to All.


setFilteredTodos([...todos].filter(t => t.id !== newTodoIdAvailable));
setTodos([...todos, responseFromAddedTodo]);
setFilteredTodos([...todos, responseFromAddedTodo]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the code is a little confusing, you're manipolating the filteredTodos too much, making the rendered todos messy. Try imagining what you want to be rendered when you add a new todo, think of all scenarios, try adding a new todo when you have each filter on, and what you want to be rendered on the screen while adding the new todo in each case.


function handleToggleAllTodos() {
const successfulUpdatedTodo: number[] = [];
const hasAllSameStatus = todos.every(t => t.completed);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not actually a mistake, just an possible improvement.

add a Complete to the name of the variable. You want it to have the value true if all the todos have status completed. When you name the varibale hasAllSameStatus it gives the impression that if the status of all the todos is not completed, it would be true as well.

@italomagno italomagno requested a review from raulriato November 19, 2024 00:11
Copy link

@raulriato raulriato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Good job! Just an advice for next projects.

const [filteredTodos, setFilteredTodos] = useState<Todo[]>([]);
const [error, setError] = useState<string | null>(null);
const [editingTodosId, setEditingTodosId] = useState<number[]>([]);
const [isFooterActive, setIsFooterActiveFilter] = useState(false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to keep the name of the variable and the setter with the same name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants